<template>
  <div id="app">
    <!-- <keep-alive> -->
      <router-view></router-view>
    <!-- </keep-alive> -->
  </div>
</template>

<script>
import storage from '@/common/js/storage'
import { isVaild } from '@/api/login'

export default {
  name: 'App',
  methods: {
    loginMessage() {
      let user = storage.session.get('user')

      if (user && !user.overdueMessage && !isVaild() && this.$route.path === '/login') {
        this.$message.warning(`${user.name} 账号已过期！`)

        storage.session.set('user', Object.assign(user, {
          overdueMessage: true
        }))
      }

      if (user && !user.welcomeMessage && isVaild()) {
        this.$message.success(`欢迎, ${user.name} 登录！`)

        storage.session.set('user', Object.assign(user, {
          welcomeMessage: true
        }))
      }
    }
  },
  watch: {
    '$route': {
      handler: function() {
        this.loginMessage()
      },
      immediate: true
    }
  }
}
</script>

<style>
</style>
